<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <!-- <script src="./016_reduce的使用.js"></script> -->
  <ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
  </ul>
  <script>
    let lis = document.querySelectorAll("ul")[0].children;
    // for(let i = 0;i<lis.length;i++){
    //   lis[i].addEventListener("click",()=>console.log(i))
    // }
    for(var i = 0;i<lis.length; i++){
      (function(index){
        lis[index].onclick = function(){
          console.log(index)
        }
      })(i);//给每一个索引绑定一个i值
    }

  </script>
  <button id="btn">点击</butto>
  <script>
    var user = {
      data:[{name:"turnip",age:18},{name:"kang",age:19}],
      clickHandler:function(event){
        var randomNum = ((Math.random()*2|0)+1)-1
        console.log(this.data[randomNum].name+""+this.data[randomNum].age);
      }
    }
    document.querySelector("#btn").addEventListener("click",user.clickHandler.bind(user))

  </script>

</body>
</html>